﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Threading.Tasks;

namespace Gems
{
    public static class SocketExtensions
    {
        public static Task<int> SendAsync2(this Socket s, byte[] data)
        {
            return Task.Factory.FromAsync((d, c, state) => s.BeginSend(d, 0, d.Length, SocketFlags.None, c, state),
                                          r => s.EndSend(r), data, null);
        }

        public static Task ConnectAsync2(this Socket s, EndPoint endpoint)
        {
            return Task.Factory.FromAsync((ep, c, state) => s.BeginConnect(ep, c, state), (ar) => s.EndConnect(ar),
                                          endpoint, null);
        }
    }
}
